package com.reviewit.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.bson.types.ObjectId;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;

@Entity("documents")
public class Document implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private ObjectId id;
	@Reference
	private User owner;
	private String title;
	private String description;
	private String url;
	private int score;
	private int viewCount;
	@Reference
	private DocType type;
	@Reference
	private DocLicence licence;
	private Collection<User> visibleToUsers;
	@Reference(ignoreMissing = true)
	private List<Tag> tags;
	private Date creationDate;
	
	public Document() {
		this.tags = new ArrayList<Tag>();
	}

	public Document(ObjectId id) {
		super();
		this.id = id;
	}

	public Document(ObjectId id, User owner, String title, String description,
			DocType type, DocLicence licence, Collection<User> visibleToUsers,
			List<Tag> tags) {
		super();
		this.id = id;
		this.title = title;
		this.description = description;
		this.type = type;
		this.licence = licence;
		this.visibleToUsers = visibleToUsers;
		this.tags = tags;
		this.owner = owner;
	}

	public ObjectId getId() {
		return id;
	}

	public void setId(ObjectId id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getViewCount() {
		return viewCount;
	}

	public void setViewCount(int viewCount) {
		this.viewCount = viewCount;
	}

	public DocType getType() {
		return type;
	}

	public void setType(DocType type) {
		this.type = type;
	}

	public DocLicence getLicence() {
		return licence;
	}

	public void setLicence(DocLicence licence) {
		this.licence = licence;
	}

	public Collection<User> getVisibleToUsers() {
		return visibleToUsers;
	}

	public void setVisibleToUsers(Collection<User> visibleToUsers) {
		this.visibleToUsers = visibleToUsers;
	}

	public List<Tag> getTags() {
		return tags;
	}

	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}

	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Document other = (Document) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public String toString() {
		return this.getTitle();
	}
	
}